import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

//配置路由信息
const routes = [
    /**
     * @param path 链接路径
     * @param name 路由名称
     * @param component 映射的组件
     * @param props 组件参数(与router解耦)
     * @param redirect 跳转路径
     * @param child 嵌套路由信息
     */
    {
        path: "/",
        name: "login",
        meta: {
            title: "KG-登录"
        },
        component: () => import("../views/login")
    },
    {
        path: "/home",
        name: "home",
        component: () => import("../views/home"),
        children: [
            // home组件的下级组件包括侧栏所要使用的每一个主题内容
            {
                path: "homePage",
                name: "homePage",
                meta: {
                    title: "KG-主页"
                },
                component: () => import("../components/homePage")
            },
            {
                path: "HelloWorld",
                name: "HelloWorld",
                meta: {
                    title: "KG-D3测试"
                },
                component: () => import("../components/HelloWorld")
            },
            {
                path: "templateBench",
                name: "templateBench",
                meta: {
                    title: "KG-模板工作台"
                },
                component: () => import("../components/templateBench")
            }
        ]

    },
];

/**
 * 新建路由方法
 */
const createRouter = () => new VueRouter({
    // mode: 'history', // require service support
    scrollBehavior: () => ({y: 0}),
    routes: routes
});

/**
 * 重置路由方法
 */
export function resetRouter() {
    const newRouter = createRouter();
    router.matcher = newRouter.matcher; // reset router
}


// 创建一个路由
const router = createRouter();

export default router;